package sivak.net.proc.dyn.fibonacci_tree;



/**
 * Created with IntelliJ IDEA.
 * User: ZefiR
 * Date: 23.01.13
 * Time: 22:52
 * To change this template use File | Settings | File Templates.
 */
public class FibonacciTreeUtils
{
    static int count = 0;
    public static void main(String[] args) {
        TreeNode treeNode = generateArg(5);
        TreeNode treeNode1 = generateRes(3);
        TreeNode treeNode2 = generateNum(10);
        printTreeNode(treeNode);
        System.out.println();
        printTreeNode(treeNode1);
        System.out.println();
        printTreeNode(treeNode2);
    }

    public static TreeNode generateArg(int k) {
        if (k < 2) {
            return new TreeNode(k, null, null);
        }
        return new TreeNode(k, generateArg(k - 2), generateArg(k - 1));
    }

    public static TreeNode generateRes(int k) {
        if (k < 2) {
            return new TreeNode(k, null, null);
        }
        return new TreeNode(generateRes(k - 2).value + generateRes(k - 1).value, generateRes(k - 2), generateRes(k - 1));
    }

    public static TreeNode generateNum(int k) {
        count++;
        if (k < 2)
            return new TreeNode(count, null, null);
        return new TreeNode(count, generateNum(k - 2), generateNum(k - 1));
    }

    public static void printTreeNode(TreeNode treeNode) {
        System.out.print("{" + treeNode.value);
        if (treeNode.left != null) {
            System.out.print(", ");
            printTreeNode(treeNode.left);
        } else System.out.print(", null");

        if (treeNode.right != null) {
            System.out.print(", ");
            printTreeNode(treeNode.right);
        } else System.out.print(", null");
        System.out.print("}");
    }
 }